package com.codyy.lib.base.application

import android.os.Bundle
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.codyy.lib.base.application.databinding.ActivityMainDbBinding
import com.codyy.lib.base.application.repos.viewmodel.ReposViewModel
import com.codyy.lib_common.base.activity.BaseDataBindingActivity
import com.kennyc.view.MultiStateView
import kotlinx.android.synthetic.main.activity_main_db.*
import org.koin.androidx.viewmodel.ext.android.viewModel

class MainActivityWithDatabinding : BaseDataBindingActivity<ActivityMainDbBinding>() {

    private val mViewModel: ReposViewModel by viewModel()
    override fun getLayoutRes(): Int =R.layout.activity_main_db
    override fun onCreate(savedInstanceState: Bundle?) {
        setStatusBarDarkFont(true)
        super.onCreate(savedInstanceState)
    }
    override fun initView() {
        mDataBinding.vm=mViewModel
        mMultipleStatusView.getView(MultiStateView.ViewState.ERROR)?.findViewById<TextView>(R.id.tv_retry)
            ?.setOnClickListener {
                mViewModel.mStateLiveData.value = MultiStateView.ViewState.LOADING
            }
    }

    override fun initData() {
        super.initData()
//        mViewModel.getOrderList().observe(this, Observer {
//           mViewModel.adapter.data=it.data.toMutableList()
//        })
        mViewModel.getOrderListWithLaunch()
        mDataBinding.viewStub.setOnInflateListener { stub, inflated ->
            if(inflated is RecyclerView){
                inflated.addItemDecoration(mViewModel.mDividerItemDecoration)
            }
        }
    }
}
